//
//  ST_PinterestHomeFilterModel.swift
//  btvideo
//
//  Created by mac on 2020/5/12.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

/**
 选项的数据
 */
class PinterestFilterOptionModel:NSObject{

    var remoteKey = ""
    
    var keyString = ""
    
    
    
//    两个值使用 minValue ... maxValue
    var minValue = 0
    var maxValue = 0
    
    var value = ""
    var selectedId:String?
    
    
    var isOn = false
}



class ST_PinterestHomeFilterModel: NSObject {
    
    private static let resetModel = ST_PinterestHomeFilterModel()
    
    func isEqualResetFilter() -> Bool {
        
        let resetModel = ST_PinterestHomeFilterModel.resetModel
        
        
        if resetModel.genderFilter.selectedId != self.genderFilter.selectedId{
            return false
        }
        
        
        if resetModel.neighbor.isOn != self.neighbor.isOn{
            return false
        }
        
        if resetModel.faceDetected.isOn != self.faceDetected.isOn{
            return false
        }
        
        if resetModel.haveMyloved.isOn != self.haveMyloved.isOn{
            return false
        }
        
        
        if resetModel.distance.value != self.distance.value{
            return false
        }
        
        if resetModel.age.minValue != self.age.minValue || resetModel.age.maxValue != self.age.maxValue{
            return false
        }
        
        
        if resetModel.stature.minValue != self.stature.minValue || resetModel.stature.maxValue != self.stature.maxValue{
            return false
        }
        
        if resetModel.ST_Zodiac.selectedId != self.ST_Zodiac.selectedId{
            return false
        }
        
        if resetModel.Education.selectedId != self.Education.selectedId{
            return false
        }
        
        if resetModel.career.selectedId != self.career.selectedId{
            return false
        }
        
        if resetModel.seek.selectedId != self.seek.selectedId{
            return false
        }
        
        return true
    }
    
    func conver_to_param()->[String:Any]{
        
        var param = [String:Any]()
        
        if self.faceDetected.isOn{
            param.updateValue(3, forKey: "face_state")
        }else{
            param.updateValue(1, forKey: "face_state")
        }
        
        if self.isEqualResetFilter(){
            return param
        }
        
        if let id = self.genderFilter.selectedId{
            param.updateValue(id, forKey: "gender")
        }
        
        
        
        if self.haveMyloved.isOn{
            param.updateValue(1, forKey: "have_like_feature")
        }
        
        if self.neighbor.isOn{
            
            param.updateValue(1, forKey: "is_same_city")
        }
        
        param.updateValue(distance.value, forKey: "distance_end")
        
        param.updateValue(age.minValue, forKey: "age_start")
        param.updateValue(age.maxValue, forKey: "age_end")
        
//        身高 在默认值最外拖动 才发送请求
        if stature.minValue > ST_PinterestHomeFilterModel.resetModel.stature.minValue || stature.maxValue < ST_PinterestHomeFilterModel.resetModel.stature.maxValue{
            
            param.updateValue(stature.minValue, forKey: "height_start")
            param.updateValue(stature.maxValue, forKey: "height_end")
        }
        
        if let id = ST_Zodiac.selectedId,id != "0"{
            param.updateValue(id, forKey: "constellation")
        }
        
        if let id = Education.selectedId,id != "0"{
            param.updateValue(id, forKey: "personal_education")
        }
        
        if let id = career.selectedId,id != "0"{
            param.updateValue(id, forKey: "job_id")
        }
        
        if let id = seek.selectedId,id != "0"{
            param.updateValue(id, forKey: "personal_want")
        }
        
        return param
        
    }
    
//    MARK: - Properties
    
    lazy var distance:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "距离"
        v.value = 200.string
        return v
    }()
    
    lazy  var genderFilter:PinterestFilterOptionModel = {
       let m = PinterestFilterOptionModel()

        m.keyString = "对你显示"
        
        if ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex == .male{
            m.value = "女"
            m.selectedId = "2"
        }else{
            m.value = "男"
            m.selectedId = "1"
        }
        return m
    }()
    
    lazy var faceDetected:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "只看真人"
        v.isOn = true
        return v
    }()
    
    lazy var haveMyloved:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "只看有我喜欢的特质"
        v.isOn = false
        return v
    }()
    
    lazy var neighbor:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "只看同城"
        v.isOn = false
        return v
    }()
    
    lazy var age:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "年龄"
        v.minValue = 18
        v.maxValue = 50
        return v
    }()
    
    
    
    
    lazy var stature:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "身高"
        v.minValue = 150
        v.maxValue = 190
        return v
    }()
    
    
    lazy var ST_Zodiac:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "星座"
        v.remoteKey = "constellation"
        
        v.selectedId = "0"
        v.value = "全部"
        return v
    }()
    
    lazy var Education:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "学历"
        v.remoteKey = "personal_education"
        
        v.selectedId = "0"
        v.value = "全部"
        return v
    }()
    
    lazy var career:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "职业"
        v.remoteKey = "jobs"
        
        v.selectedId = "0"
        v.value = "全部"
        return v
    }()
    
    lazy var seek:PinterestFilterOptionModel = {
        let v = PinterestFilterOptionModel()
        v.keyString = "想要寻求"
        v.remoteKey = "personal_want"
        
        v.selectedId = "0"
        v.value = "全部"
        return v
    }()
    
    
}
